<?php

declare (strict_types=1);

namespace app\member\model;

use think\admin\Model;
use think\model\relation\HasOne;
use app\api\controller\Base;

/**
 * 用户模型
 * @class ImsEweiShopMerchUser
 * @package think\admin\model
 */

class ImsEweiShopMemberCart extends Model
{
    protected $createTime = 'createtime';
    protected $updateTime = false;

    /**
     * 日志名称
     * @var string
     */
    protected $oplogName = '会员购物车';

    /**
     * 商户信息管理
     * @var string
     */
    protected $oplogType = '会员购物车';

    /**
     * 格式化创建时间
     * @param mixed $value
     * @return string
     */
    public function getCreateAtAttr($value): string
    {
        return format_datetime($value);
    }

    public static function formatDatas($data=[]){

        $newData = [];
        foreach ($data as $k => $v) {
            $newData[] = [

                "id" => $v['id'],
                "select" => $v['select'],
                "goods_id" => $v['goods_id'],
                "logo" => Base::getImageFullUrl($v['thumb']),
                "title" => $v['title'],
                "number_stock" => $v['number_stock'],
                "price_discount" => $v['price'],
                "price" => $v['price'],
                "total_price" => $v['price']*$v['goods_number'],
                "goods_number" => $v['goods_number'],
                "isnew" => $v['isnew'],
                "ishot" => $v['ishot'],
                "isdiscount" => $v['isdiscount'],
                "isrecommand" => $v['isrecommand']
            ];
        }

        return $newData;
    }
}